﻿using System;
using System.Collections;
using System.Collections.Generic;
using BLL.RF.JointingCheck;
using Model.RF.JointingCheck;
using CrystalDecisions.CrystalReports.Engine;

public partial class ProductAssemble_ViewAssemble_JointingCheck_JointingCheckStatisticbyDT : System.Web.UI.Page
{
    private DateTime dt1
    {
        get { return DateTime.Parse(ViewState["starttime"].ToString()); }
        set { ViewState["starttime"] = value; }
    }
    private DateTime dt2
    {
        get { return DateTime.Parse(ViewState["stoptime"].ToString()); }
        set { ViewState["stoptime"] = value; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.Page.Unload += new EventHandler(Page_Unload);
        }
    }

    void Page_Unload(object sender, EventArgs e)
    {
        this.CrystalReportSource1.Dispose();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        dt1 = DateTime.Parse(this.TextBox1.Value.Trim());
        dt2 = DateTime.Parse(this.TextBox2.Value.Trim());
        IList<JointingFailure_QInfo> list = GetQData();
        if (list.Count > 0)
            BindQCR(list);
        else
            ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('数据为空！');</script>");
    }

    private void BindQCR(IList<JointingFailure_QInfo> list)
    {
        this.CrystalReportSource1.ReportDocument.Load(Server.MapPath("../QCFixedCheckStatisticbyDT.rpt"));

        TextObject txtTestTime = (TextObject)this.CrystalReportSource1.ReportDocument.ReportDefinition.ReportObjects["Text1"];
        txtTestTime.Text = dt1.ToString() + "-" + dt2.ToString();

        this.CrystalReportSource1.ReportDocument.SetDataSource(list);
        this.CrystalReportSource1.DataBind();
        this.CrystalReportViewer1.ReportSource = CrystalReportSource1;
        this.CrystalReportViewer1.DataBind();
        this.CrystalReportViewer1.Visible = true;
    }

    private IList<JointingFailure_QInfo> GetQData()
    {
        IList<JointingFailure_QInfo> oprs = new List<JointingFailure_QInfo>();
        JointingFailure_Q opr = new JointingFailure_Q();
        oprs = opr.GetJointingFailure_Q_JointingCheckbyDT(dt1, dt2);
        return oprs;
    }
}
